export const baseURL = 'https://zys.elecul.com/api';
export const baseKey = 'authori-zation';
export const baseStr = 'Bearer ';
const appid = 'wx1cd57328fcb86010'
export const myRequest = (options) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseURL + options.url, //接口地址：前缀+方法中传入的地址
			method: options.method || 'GET', //请求方法：传入的方法或者默认是“GET”
			data: options.data || {}, //传递参数：传入的参数或者默认传递空集合
			header: {
				[baseKey]: baseStr + uni.getStorageSync('token') //自定义请求头信息
			},
			success: (res) => {
				if(res.data.status === 110002){
					uni.clearStorageSync('token')
					const local = encodeURIComponent(
						`https://zys.elecul.com/h5/#/pages/authori/authori`
					);
					window.location.href =
						"https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
						appid +
						"&redirect_uri=" +
						local +
						"&response_type=code&scope=snsapi_userinfo&connect_redirect=1#wechat_redirect";
				}else{
					resolve(res.data)
				}
			},
			// 这里的接口请求，如果出现问题就输出接口请求失败
			fail: (err) => {
				reject(err)
			}
		})
	})
}